using System.Collections.Generic;
using System.Data;
using MallInteractiveMap.ClientDataHandler;
using MallInteractiveMap.Common;
using MallInteractiveMap.DTO;
using MallInteractiveMap.Language;

namespace MallInteractiveMap.CMSWebClient.Presenter
{
    public class MapPresenter
    {
        public MapPresenter()
        {
        }
        public List<DTOMap> GetMaps()
        {
            string error = string.Empty;
            List<DTOMap> map = ClientData.GetMap(new QueryParamList(), ref error);
            if (!string.IsNullOrEmpty(error))
            {

            }
            return map;
        }
        public List<DTOMap> GetMaps(int Id)
        {
            string error = string.Empty;
            QueryParamList param = new QueryParamList();
            param.Add(new QueryParamObj() { ParamName = "Id", DBType = DbType.Int32, ParamValue = Id });
            List<DTOMap> map = ClientData.GetMap(param, ref error);
            if (!string.IsNullOrEmpty(error))
            {

            }
            return map;
        }
        public bool SetData(DTOMap oMap)
        {
            QueryParamList param = new QueryParamList();
            if (!oMap.IsNew)
                param.Add(new QueryParamObj() { ParamName = "Id", DBType = DbType.Int32, ParamValue = oMap.Id });
            else
            {
                param.Add(new QueryParamObj() { ParamName = "LanguageType", DBType = DbType.Int32, ParamValue = LanguageLoader.CurrentLanguageType });
            }
            param.Add(new QueryParamObj() { ParamName = "Title", DBType = DbType.String, ParamValue = oMap.Title });
            param.Add(new QueryParamObj() { ParamName = "ShopCount", DBType = DbType.Int32, ParamValue = oMap.ShopCount });
            param.Add(new QueryParamObj() { ParamName = "Description", DBType = DbType.String, ParamValue = oMap.Description });
            param.Add(new QueryParamObj() { ParamName = "LastUpdated", DBType = DbType.DateTime, ParamValue = oMap.LastUpdated });
            string error = string.Empty;
            string spName = oMap.IsNew ? "INSERTMap " : "UPDATEMap";
            bool isSuccess = ClientData.SetData(param, spName, ref error);
            return string.IsNullOrEmpty(error) & isSuccess;
        }
        public bool Delete(int Id)
        {
            string error = string.Empty;
            QueryParamList param = new QueryParamList();
            param.Add(new QueryParamObj() { ParamName = "Id", DBType = DbType.Int32, ParamValue = Id });
            bool isSuccess = ClientData.SetData(param, "DELETEMap", ref error);
            return string.IsNullOrEmpty(error) & isSuccess;
        }
    }
}
